<?php
/**
 * 具体产品
 * @author Administrator
 *
 */
class Product{
	private $_parts;
	
	public function __construct(){
		$this->_parts = array();
	}
	
	public function add($part){
		return array_push($this->_parts,$part);
	}
	
	public function show(){
		foreach ($this->_parts as $k=>$v){
			echo $v.'<br/>';
		}
	}
}
/**
 * 抽象建造者
 * @author Administrator
 *
 */
abstract class Builder{
	public abstract function buildHead();
	public abstract function buildBody();
	public abstract function buildFoot();
	public abstract function getResult();
}
/**
 * 具体建造者
 * @author Administrator
 *
 */
class BirdBuilder extends Builder{
	private $birdProduct;
	
	public function __construct(){
		$this->birdProduct = new Product();
	}
	
	public function buildHead(){
		$this->birdProduct->add('鸟头');
	}
	public function buildBody(){
		$this->birdProduct->add('鸟身');
	}
	public function buildFoot(){
		$this->birdProduct->add('鸟脚');
	}
	public function getResult(){
		return $this->birdProduct;
	}
}

/**
 * 具体建造者
 * @author Administrator
 *
 */
class FishBuilder extends Builder{
	private $fishProduct;

	public function __construct(){
		$this->fishProduct = new Product();
	}

	public function buildHead(){
		$this->fishProduct->add('鱼头');
	}
	public function buildBody(){
		$this->fishProduct->add('鱼身');
	}
	public function buildFoot(){
		$this->fishProduct->add('鱼尾');
	}
	public function getResult(){
		return $this->fishProduct;
	}
}
/**
 * 指挥者
 * @author Administrator
 *
 */
class Director{
	public function buildProduct($builder){
		$builder->buildHead();
		$builder->buildBody();
		$builder->buildFoot();
		return $builder->getResult();
	}
}

header("Content-Type:text/html;charset=utf-8");
$director = new Director();
$pro1 = $director->buildProduct(new FishBuilder());
$pro1->show();

$pro1 = $director->buildProduct(new BirdBuilder());
$pro1->show();